import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/pages/nft_pages/danation/danation_choose_tools_controller.dart';

import 'package:yysk_app/routes/global_controller.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/utils/js_tool.dart';

import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/widget/button_widget.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';
import 'package:yysk_app/widget/lazy_network_image.dart';

class DanationChooseToolsPage extends GetView<DanationChooseToolsController> {
  static const path = '/danationChooseTools';

  const DanationChooseToolsPage({super.key});

  @override
  Widget build(BuildContext context) {
    double top = MediaQuery.of(context).padding.top;

    return PopScope(
      canPop: false,
      child: Scaffold(
        bottomNavigationBar: Container(
          padding: EdgeInsets.fromLTRB(20, 10, 10, 20),
          child: Obx(
            () => (Flex(
              direction: Axis.horizontal,
              children: [
                Expanded(
                  flex: 1,
                  child: RichText(
                    text: TextSpan(
                      style: DefaultTextStyle.of(context).style,
                      children: <TextSpan>[
                        TextSpan(
                          text: '已选中：',
                          style: TextStyle(
                            color: Color(0xFF222222),
                            fontSize: 14.px,
                          ),
                        ),
                        TextSpan(
                          text: controller.number.toString(),
                          style: TextStyle(
                            color: Color(0xFF222222),
                            fontSize: 24.px,
                          ),
                        ),
                        TextSpan(
                          text: ' 条',
                          style: TextStyle(
                            color: Color(0xFF222222),
                            fontSize: 14.px,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(2),
                    ),
                    width: 200,
                    height: 54,
                    child: ButtonWidget(
                      label: '批量转赠',
                      width: 200.px,
                      height: 53.px,
                      fontSize: 16.px,
                      imageBg: 'static/images/batch_btn_bg.png',
                      contentType: ContentType.other,
                      paddingText: EdgeInsets.only(left: 16.px),
                      fontColor: AppColors.backgroundColorBlack,
                      onPressed: () {},
                    ),
                  ),
                ),
              ],
            )),
          ),
        ),
        body: Stack(
          children: [
            SizedBox(
              width: context.width,
              child: ImageAssetWidget(
                width: 375.px,
                height: 200.px,
                imageUrl: 'static/images/setting/give_top_bg@2x.png',
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: top),
              child: Obx(
                () => Column(
                  children: [
                    CustomAppBar2(
                      title: '批量转赠',
                      context: context,
                      beforBack: () {
                        Navigator.of(context).pop();
                      },
                    ),

                    Expanded(child: _listViewWidget(context)),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _listViewWidget(BuildContext context) {
    return ListView.builder(
      padding: EdgeInsets.zero,
      itemCount: controller.dataList.length,
      itemBuilder: (context, index) {
        final item = controller.dataList[index];

        return GestureDetector(
          onTap: () {},
          child: Container(
            padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
            margin: EdgeInsets.fromLTRB(14, 9, 14, 0),
            height: 100.px,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(20.px),
              border: Border.all(color: Colors.white12),
              color: AppColors.backgroundColorLightGrey,
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,

              children: [
                Padding(
                  padding: EdgeInsets.fromLTRB(12.px, 12.px, 0, 12.px),
                  child: LazyImage(
                    imageUrl: item.url,
                    width: 65,
                    height: 65,
                    boxFit: BoxFit.cover,
                  ),
                ),
                Column(
                  children: [
                    SizedBox(
                      child: Text(
                        item.title,
                        style: TextStyle(
                          color: AppColors.backgroundColorBlack,
                          fontSize: 18.px,
                          overflow: TextOverflow.ellipsis,
                        ),
                        textAlign: TextAlign.start,
                      ),
                    ),
                    SizedBox(
                      child: Text(
                        item.time,
                        style: TextStyle(
                          color: AppColors.fontColorGrey,
                          fontSize: 12.px,
                          overflow: TextOverflow.ellipsis,
                        ),
                        textAlign: TextAlign.start,
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  width: 35,
                  height: 35,
                  child: IconButton(
                    onPressed: () {},
                    icon: Image.asset(
                      item.isChoose.value
                          ? 'static/images/setting/choose_selected@2x.png'
                          : 'static/images/setting/choose_nomal@2x.png',
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
